<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">


<section class="content-header"><h1>月提报计划统计</h1></section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm"  method="get">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>物料描述</label>
                                    <input type="hidden" style="display: none" name="rppMatDescArrayStr" />
                                    <div class="form-control"  name="rppMatDescArraySelect"
                                            style="OVERFLOW-Y: auto; OVERFLOW-X:hidden;width: 196px!important; display: inline-block; height:34px!important;-webkit-border-radius: 0 !important;-moz-border-radius: 0 !important;border-radius: 0 !important;" >
                                    </div>
                                    <lable>
                                    <button type="button"
                                            class="btn-success"
                                            style="font-size: 22px;
                                                font-weight: 900;
                                                width:36px!important;
                                                height: 36px!important;
                                                border-radius: 5px"
                                            name="addRppMatDescArraySelect">＋</button>
                                    <button type="button"
                                            class="btn-danger"
                                            style="font-size: 22px;
                                                font-weight: 900;
                                                width:36px!important;
                                                height: 36px!important;
                                                border-radius: 5px"
                                            name="subtractRppMatDescArraySelect">－</button>
                                    </lable>
                                </div>
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <!--<input type="text" name="rppProjectCode" class="form-control" placeholder="请输入项目编号">-->
                                    <input type="hidden" style="display: none" name="rppProjectCodeArrayStr" />
                                    <div class="form-control"  name="rppProjectCodeArraySelect"
                                         style="OVERFLOW-Y: auto; OVERFLOW-X:hidden;width: 196px!important; display: inline-block; height:34px!important;-webkit-border-radius: 0 !important;-moz-border-radius: 0 !important;border-radius: 0 !important;" >
                                    </div>
                                    <lable>
                                        <button type="button"
                                                class="btn-success"
                                                style="font-size: 22px;
                                                font-weight: 900;
                                                width:36px!important;
                                                height: 36px!important;
                                                border-radius: 5px"
                                                name="addRppProjectCodeArraySelect">＋</button>
                                        <button type="button"
                                                class="btn-danger"
                                                style="font-size: 22px;
                                                font-weight: 900;
                                                width:36px!important;
                                                height: 36px!important;
                                                border-radius: 5px"
                                                name="subtractRppProjectCodeArraySelect">－</button>
                                    </lable>
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="rppProjectName" class="form-control" placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>计划员</label>
                                    <input  type="text" name="rppPlanner" class="form-control" placeholder="请输入计划员">
                                </div>
                                <div class="form-group">
                                    <label>标准号</label>
                                    <input type="text" name="rppStandardNo" class="form-control" placeholder="请输入标准号">
                                </div>
                                <div class="form-group">
                                    <label>提报状态</label>
                                    <select name="rppUseStock" class="form-control">
                                        <option value="0">无状态</option>
                                        <option value="1">使用库存</option>
                                        <option value="2">正常提报</option>
                                        <option value="3">暂不提报</option>
                                        <option value="" selected="">全部</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>分类</label>
                                    <select name="rppTypeId" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option th:each="type : ${categories}" th:value="${type.dicId}" th:text="${type.dicName}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>生产状态</label>
                                    <select name="rppProjectState" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="-1">无状态</option>
                                        <option value="1">未开始</option>
                                        <option value="2">执行中</option>
                                        <option value="3">已完成</option>
                                        <option value="4">取消</option>
                                        <option value="5">暂缓</option>
                                    </select>
                                </div>
                                <div class="form-group" >
                                    <label>单据状态</label>
                                    <select name="rppStatus" class="form-control">
                                        <option value="">全部</option>
                                        <option value="2" selected="selected">未提交</option>
                                        <option value="3">已提交</option>
                                    </select>
                                </div>
                                <div class="form-group" >
                                    <label>指定状态</label>
                                    <select name="rppIsFlag" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option value="1">已指定</option>
                                        <option value="0">未指定</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>提报日期</label>
                                    <input type="text" class="form-control datepicker" name="startTime" readonly="readonly"/>
                                    <span> 至 </span>
                                    <input type="text" class="form-control datepicker" name="endTime" readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>

                        </div>
                    </form>
                    <div class="row" id="toolbar">
                        <div class="form-inline">
                            <a id="a-export" shiro:hasPermission="buy:planedit:export" href="javascript:void(0);" class="btn btn-primary pull-right" style="margin-right: 10px">
                                <span class="Bold">暂缓导出</span>
                            </a>

                            <a shiro:hasPermission="buy:planedit:edit" href="javascript:void(0);" class="btn btn-success pull-right" style="margin-right: 10px" onclick="openImportUpdateModal()">
                                <span class="Bold">暂缓导入</span>
                            </a>
                            <a shiro:hasPermission="buy:planedit:assign" href="javascript:void(0);" class="btn btn-warning pull-right" style="margin-right: 10px" onclick="openOutAssignModal()">
                                <span class="Bold">批量库存指定</span>
                            </a>
                            <a href="javascript:void(0);" class="btn btn-info pull-right" style="margin-right: 10px" onclick="openMapModal()">
                                <span class="Bold">拆分记录</span>
                            </a>
                            <a shiro:hasPermission="buy:planexport:add" href="javascript:void(0);" class="btn btn-success pull-right" style="margin-right: 10px" onclick="openImportModal()">
                                <span class="Bold">导入</span>
                            </a>
                            <a shiro:hasPermission="buy:planexport:add" href="javascript:void(0);" class="btn btn-primary pull-right" style="margin-right: 10px" onclick="openCreateModal()">
                                <span class="Bold">添加</span>
                            </a>
                            <a shiro:hasPermission="buy:planedit:edit" href="javascript:void(0);" class="btn btn-warning pull-right" style="margin-right: 10px" onclick="openBatchModal()">
                                <span class="Bold">修改状态</span>
                            </a>
                            <a shiro:hasPermission="buy:planedit:edit" href="javascript:void(0);" class="btn btn-success pull-right" style="margin-right: 10px" onclick="commitAll()">
                                <span class="Bold">全部提交</span>
                            </a>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    var table, markTable, mapTable, reportPlanTable, markInfoTable, batchTable, outAssignTable, assignPlanTable;
    var reportState = ['','使用库存','正常提报','暂不提报','甲供'];
    var projectState = ['无状态','执行中','未开始','暂缓','已完成','取消'];
    var projectColors = ['',"label-warning", "label-default", "label-danger", "label-success"];
    var reportColors = ['',"label-warning", "label-info", "label-primary"];
    var infoUrl = ctx + 'buy/editReportPlan/info/';

    /** 添加模态框 */
    function openCreateModal() {
        js.modal.open("modal-create");
    }
    /** 导入模态框 */
    function openImportModal() {
        js.modal.open("modal-import");
    }
    /** 导入模态框 */
    function openImportUpdateModal() {
        js.modal.open("modal-import-update");
    }

    /** 指定计划模态框 */
    function assignPlan() {
        openAssignPlanModal($("#editReportPlanForm input[name=rppId]").val());
    }
    /** 指定计划模态框 */
    function assignPlanSplit() {
        openAssignPlanModal($("#editSplitReportPlanForm input[name=rppId]").val());
    }
    /** 指定计划模态框 */
    function openAssignPlanModal(id) {
        js.post({
            url: ctx + "buy/editReportPlan/id",
            data: {
                id: id
            },
            success:function(result) {
                $("#assignPlanForm").fillSpan(result);
                $("#assignPlanForm").fillData(result);
                js.table.search(assignPlanTable);
                js.modal.open("modal-assign-plan");
            }
        })
    }
    /** 指定计划 */
    function assignPlanApply(id) {
        js.post({
            url: ctx + "buy/editReportPlan/assignPlan",
            data: {
                rppId: $("#assignPlanForm input[name=rppId]").val(),
                sppId: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.modal.hide("modal-assign-plan");
                    js.modal.hide("modal-edit");
                    js.modal.hide("modal-edit-split");
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }

    /** 修改模态框 */
    function openEditReportPlanModal(id, status) {
        js.post({
            url: ctx + "buy/editReportPlan/id",
            data: {
                id: id
            },
            success:function(result) {
                /** 修改计划员权限 */
                if(hasP('buy:planedit:change')){
                    $("#editReportPlanForm input[name='rppPlanner']").removeAttr('readonly');
                }else {
                    $("#editReportPlanForm input[name='rppPlanner']").attr('readonly','readonly');
                }
                if (result.rppStatus == 3) {
                    $("#rppUseStockByModal").hide();
                }else {
                    $("#rppUseStockByModal").show();
                }

                /** 正常提报显示指定计划按钮， 否则隐藏 */
                if (result.rppUseStock == 2) {
                    $(".assign-plan").show();
                }else {
                    $(".assign-plan").hide();
                }
                if (status === 1) {
                    $("#editReportPlanForm").fillData(result);
                    js.modal.open("modal-edit");
                    setTimeout(function () {
                        js.validate.validing("editReportPlanForm");
                    }, 500);
                }else if (status === 2) {
                    $("#editSplitReportPlanForm").fillSpan(result);
                    $("#editSplitReportPlanForm").fillData(result);
                    js.modal.open("modal-edit-split");
                }
            }
        });
    }
    /** 修改提报计划 */
    function update() {
        js.validSubmit({
            formId: "editSplitReportPlanForm",
            url: ctx + "buy/editReportPlan/edit",
            data: new FormData($("#editSplitReportPlanForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    if (mapTable) {
                        js.table.refresh(mapTable);
                    }
                    js.modal.hide("modal-edit-split");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
    /** 变更提报计划模态框 */
    function openChangeReportPlanModal(id) {
        js.post({
            url: ctx + "buy/editReportPlan/id",
            data: {id: id},
            success: function (result) {
                // $("#changeReportPlanForm").fillData(result);
                $("#changeReportPlanForm").fillSpan(result);
                js.modal.open("modal-change");
                setTimeout(function () {
                    js.validate.validing("changeReportPlanForm");
                }, 500);
            }
        })
    }
    /** 修改计划员模态框 */
    function openEditPlannerModal(row) {
        $("#editPlannerForm").fillData(row);
        js.modal.open('modal-edit-planner');
    }


    /** 提交提报计划 */
    function commitReportPlan(id) {
        js.confirmPost({
            content: "确认提交吗？",
            url: ctx + "buy/editReportPlan/commit",
            data: {
                id: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    if (mapTable) {
                        js.table.refresh(mapTable);
                    }
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
    /** 批量提交提报计划 */
    function commitAll() {
        var arr = js.table.selectColumns(table, "rppId");
        if (arr.length < 1) {
            js.modal.warning("请选择要提交的计划");
            return;
        }
        js.post({
            url: ctx + "buy/editReportPlan/commitAll",
            data: {
                rppIds: js.table.selectColumns(table, "rppId")
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }
    /** 删除提报计划 - 删除待审 */
    function deleteReportPlan(id) {
        js.modal.prompt("请编辑删除原因", function (reason) {
            if (reason == null) {
                return;
            }
            if (reason) {
                js.post({
                    url: ctx + "buy/editReportPlan/delete",
                    data: {
                        id: id,
                        reason: reason
                    },
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                            js.table.refresh(table);
                            if (mapTable) {
                                js.table.refresh(mapTable);
                            }
                        } else {
                            js.modal.warning(result.msg);
                        }
                    }
                })

            } else {
                js.modal.warning("请输入删除原因");
            }
        });
    }
    /** 撤消提报计划 */
    function cancelReportPlan(id) {
        js.confirmPost({
            content: "确认撤消吗？",
            url: ctx + "buy/editReportPlan/cancel",
            data: {
                id: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    if (mapTable) {
                        js.table.refresh(mapTable);
                    }
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
    /** 批量修改提报状态模态框 */
    function openBatchModal() {
        js.table.search(batchTable);
        js.modal.open("modal-batch");
    }
    /** 批量修改提报状态 */
    function batchUpdate(status) {
        var arr = js.table.selectColumns(batchTable, "rppId");
        if (arr.length < 1) {
            js.modal.warning("请选择要修改的计划");
            return;
        }
        js.post({
            url: ctx + "buy/editReportPlan/batch/status",
            data: {
                rppIds: js.table.selectColumns(batchTable, "rppId"),
                status: status
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(batchTable);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
        js.table.refresh(table);
    }


    /** 拆分模态框 */
    function openSplitModal(row) {
        $("#splitForm").fillData(row);
        $("#splitForm").fillSpan(row);
        $("#splitForm input[name=desc]").val(row.rppMatDesc);
        js.modal.open("modal-split");
    }
    /** 验证拆分后数量与原量是否相等 */
    function validNum() {
        var srcNum = +$("#splitForm span[id=rppNum]").text();
        var descNum = $("#splitForm input[name=num]").map((i, v) => +$(v).val()).get().reduce((x, y) => x + y);
        return srcNum === descNum;
    }
    /** 拆分提报计划 */
    function split() {
        js.submit({
            url: ctx + "buy/editReportPlan/split",
            data: new FormData($("#splitForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    if (mapTable) {
                        js.table.refresh(mapTable);
                    }
                    js.modal.hide("modal-split");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
    /** 拆分信息模态框 */
    function openMapModal() {
        js.table.search(mapTable);
        js.modal.open("modal-map");
    }


    /** 指定提报计划模态框 */
    function openMarkReportPlanModal(row) {
        $("#markForm").fillSpan(row);
        $("#markForm input[name=rppId]").val(row.rppId);
        $("#markForm input[name=code]").val(row.rppProjectCode);
        $("#markForm input[name=info]").val(row.rppMatDesc);
        $("#markForm input[name=rppAssignDesc]").val(row.rppAssignDesc);
        // $("#markForm input[name=standardNo]").val(row.rppStandardNo);
        js.table.search(markTable);
        js.modal.open("modal-mark");
    }
    /** 指定提报计划 */
    function mark() {
        js.post({
            url: ctx + "buy/editReportPlan/mark",
            data: {
                rppId: $("#markForm input[name=rppId]").val(),
                id: js.table.selectColumns(markTable, "id")
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.modal.hide("modal-mark")
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
    /** 查看指定信息模态框 */
    function openMarkInfoModal(row) {
        let data = [];
        data.push(row);
        js.table.load(reportPlanTable, data);
        js.table.jump(markInfoTable, infoUrl + row.rppId);
        js.modal.open("modal-info");
    }


    /** 外购件指定模态框 */
    function openOutAssignModal() {
        js.table.refresh(outAssignTable);
        js.modal.open("modal-out-assign");
    }
    /** 外购件批量指定 */
    function batchOutAssign() {
        var arr = js.table.selectColumns(outAssignTable, "rppId");
        if (arr.length < 1) {
            js.modal.warning("请选择要指定的计划");
            return;
        }
        js.post({
            url: ctx + "buy/editReportPlan/outAssign/batch",
            data: {
                rppIds: js.table.selectColumns(outAssignTable, "rppId")
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(outAssignTable);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }
    /** 外购件指定 */
    function outAssign(rppId) {
        js.confirmPost({
            content: "确认指定吗？",
            url: ctx + "buy/editReportPlan/outAssign",
            data: {
                rppId: rppId
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(outAssignTable);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }
    /**单删物料描述*/
    function deleteRppMatDescArraySelect(obj){
       var selectArr = $("#queryForm [name='rppMatDescArrayStr']").val().split(',');
       delete selectArr[$(obj).parent().attr("data-index")];
       var selectVal = selectArr.join(',');
       if(selectVal[selectVal.length-1]==','){
           selectVal=selectVal.substring(0,selectVal.length-1);
       }
        if(selectVal[0]==','){
            selectVal=selectVal.substring(1,selectVal.length);
        }
        if(selectVal.length==0){
            $("#queryForm [name='rppMatDescArraySelect']").css("width","196px");
        }
       $("#queryForm [name='rppMatDescArrayStr']").val(selectVal);
       $(obj).parent().remove();
        if($("#queryForm [name='rppMatDescArraySelect']").width()<196){
            $("#queryForm [name='rppMatDescArraySelect']").css("width","196px");
        }
    }
    /**单删项目编号*/
    function deleterppProjectCodeArraySelect(obj){
       var selectArr = $("#queryForm [name='rppProjectCodeArrayStr']").val().split(',');
       delete selectArr[$(obj).parent().attr("data-index")];
       var selectVal = selectArr.join(',');
       if(selectVal[selectVal.length-1]==','){
           selectVal=selectVal.substring(0,selectVal.length-1);
       }
        if(selectVal[0]==','){
            selectVal=selectVal.substring(1,selectVal.length);
        }
        if(selectVal.length==0){
            $("#queryForm [name='rppProjectCodeArraySelect']").css("width","196px");
        }
       $("#queryForm [name='rppProjectCodeArrayStr']").val(selectVal);
       $(obj).parent().remove();
        if($("#queryForm [name='rppProjectCodeArraySelect']").width()<196){
            $("#queryForm [name='rppProjectCodeArraySelect']").css("width","196px");
        }
    }
    /**单删项目编号*/
    function deleterppBatchFormProjectCodeArraySelect(obj){
       var selectArr = $("#batchForm [name='rppProjectCodeArrayStr']").val().split(',');
       delete selectArr[$(obj).parent().attr("data-index")];
       var selectVal = selectArr.join(',');
       if(selectVal[selectVal.length-1]==','){
           selectVal=selectVal.substring(0,selectVal.length-1);
       }
        if(selectVal[0]==','){
            selectVal=selectVal.substring(1,selectVal.length);
        }
        if(selectVal.length==0){
            $("#batchForm [name='rppProjectCodeArraySelect']").css("width","196px");
        }
       $("#batchForm [name='rppProjectCodeArrayStr']").val(selectVal);
       $(obj).parent().remove();
        if($("#batchForm [name='rppProjectCodeArraySelect']").width()<196){
            $("#batchForm [name='rppProjectCodeArraySelect']").css("width","196px");
        }
    }
    $(function () {
        /**添加物料描述*/
        $("#queryForm [name='addRppMatDescArraySelect']").click(function () {
            js.modal.prompt("请输入要搜索的物料描述",function (result) {
                if(result != null && result != ""){
                    $("#queryForm [name='rppMatDescArraySelect']").css("width","auto");
                    var idVal = $("#queryForm [name='rppMatDescArraySelect']").children("span").length;
                    var optionHtml = '<span data-index="'+idVal+'" data="'+result+'" style="font-size: 16px; margin: 5px;border: #8B8986 1px solid;border-radius: 5px;background-color: #e9e9e9;color: #333333;padding-left: 5px;padding-right: 5px" value="'+result+'">'+result+'' +
                        '<button onclick="deleteRppMatDescArraySelect(this)" onmouseover="this.style.color=\'white\';" onmouseout="this.style.color=\'#333333\';" type="button" style="outline: none;border: 0;background: transparent" name="btn_close">×</button></span>';
                    $("#queryForm [name='rppMatDescArraySelect']").append(optionHtml);
                   if($("#queryForm [name='rppMatDescArraySelect']").width()<196){
                       $("#queryForm [name='rppMatDescArraySelect']").css("width","196px");
                   }
                    var vals="";
                    $("#queryForm [name='rppMatDescArraySelect']").children("span").each(function () {
                            vals+=$(this).attr("data")+",";
                    });
                    vals=vals.substring(0,vals.length-1);
                    $("#queryForm [name='rppMatDescArrayStr']").val(vals);
                }
            })
        });

        /** 清空物料描述 */
        $("#queryForm [name='subtractRppMatDescArraySelect']").click(function () {
            $("#queryForm [name='rppMatDescArraySelect']").css("width","196px");
            $("#queryForm [name='rppMatDescArraySelect']").empty();
            $("#queryForm [name='rppMatDescArrayStr']").val('');
        });


        /**添加项目编号*/
        $("#queryForm [name='addRppProjectCodeArraySelect']").click(function () {
            js.modal.prompt("请输入要搜索的项目编号",function (result) {
                if(result != null && result != ""){
                    $("#queryForm [name='rppProjectCodeArraySelect']").css("width","auto");
                    var idVal = $("#queryForm [name='rppProjectCodeArraySelect']").children("span").length;
                    var optionHtml = '<span data-index="'+idVal+'" data="'+result+'" style="font-size: 16px; margin: 5px;border: #8B8986 1px solid;border-radius: 5px;background-color: #e9e9e9;color: #333333;padding-left: 5px;padding-right: 5px" value="'+result+'">'+result+'' +
                        '<button onclick="deleterppProjectCodeArraySelect(this)" onmouseover="this.style.color=\'white\';" onmouseout="this.style.color=\'#333333\';" type="button" style="outline: none;border: 0;background: transparent" name="btn_close">×</button></span>';
                    $("#queryForm [name='rppProjectCodeArraySelect']").append(optionHtml);
                    if($("#queryForm [name='rppProjectCodeArraySelect']").width()<196){
                        $("#queryForm [name='rppProjectCodeArraySelect']").css("width","196px");
                    }
                    var vals="";
                    $("#queryForm [name='rppProjectCodeArraySelect']").children("span").each(function () {
                        vals+=$(this).attr("data")+",";
                    });
                    vals=vals.substring(0,vals.length-1);
                    $("#queryForm [name='rppProjectCodeArrayStr']").val(vals);
                }
            })
        });

        /** 清空项目编号 */
        $("#queryForm [name='subtractRppProjectCodeArraySelect']").click(function () {
            $("#queryForm [name='rppProjectCodeSelect']").css("width","196px");
            $("#queryForm [name='rppProjectCodeArraySelect']").empty();
            $("#queryForm [name='rppProjectCodeArrayStr']").val('');
        });
        /**添加项目编号*/
        $("#batchForm [name='addRppProjectCodeArraySelect']").click(function () {
            js.modal.prompt("请输入要搜索的项目编号",function (result) {
                if(result != null && result != ""){
                    $("#batchForm [name='rppProjectCodeArraySelect']").css("width","auto");
                    var idVal = $("#batchForm [name='rppProjectCodeArraySelect']").children("span").length;
                    var optionHtml = '<span data-index="'+idVal+'" data="'+result+'" style="font-size: 16px; margin: 5px;border: #8B8986 1px solid;border-radius: 5px;background-color: #e9e9e9;color: #333333;padding-left: 5px;padding-right: 5px" value="'+result+'">'+result+'' +
                        '<button onclick="deleterppBatchFormProjectCodeArraySelect(this)" onmouseover="this.style.color=\'white\';" onmouseout="this.style.color=\'#333333\';" type="button" style="outline: none;border: 0;background: transparent" name="btn_close">×</button></span>';
                    $("#batchForm [name='rppProjectCodeArraySelect']").append(optionHtml);
                    if($("#batchForm [name='rppProjectCodeArraySelect']").width()<196){
                        $("#batchForm [name='rppProjectCodeArraySelect']").css("width","196px");
                    }
                    var vals="";
                    $("#batchForm [name='rppProjectCodeArraySelect']").children("span").each(function () {
                        vals+=$(this).attr("data")+",";
                    });
                    vals=vals.substring(0,vals.length-1);
                    $("#batchForm [name='rppProjectCodeArrayStr']").val(vals);
                }
            })
        });

        /** 清空项目编号 */
        $("#batchForm [name='subtractRppProjectCodeArraySelect']").click(function () {
            $("#batchForm [name='rppProjectCodeSelect']").css("width","196px");
            $("#batchForm [name='rppProjectCodeArraySelect']").empty();
            $("#batchForm [name='rppProjectCodeArrayStr']").val('');
        });


        /** 提报计划表 */
        table = js.table.init({
            url: ctx + "buy/editReportPlan/list",
            paginationVAlign: 'both',
            pageSize: 15,
            showColumns: true,
                showExport: false,
            onLoadSuccess:function(){
                /** 指定库存表 */
                batchTable = js.table.init({
                    id: "batch-table",
                    toolbar: '#batchBar',
                    showColumns: false,
                    queryForm: 'batchForm',
                    url: ctx + "buy/editReportPlan/list",
                    firstLoad: false,
                    columns: [
                        {
                            checkbox: true,
                            width: '30px'
                        },
                        {
                            title: '序号', field: 'id', width: '50px',
                            formatter: function (value, row, index, field) {
                                return index + 1;
                            }
                        },
                        { title: "计划员", field: 'rppPlanner'},
                        { title: "物料描述", field: 'rppMatDesc',
                            formatter: function (value, row, index, field) {
                                if (value && value.length > 50) {
                                    return '<span title="' + value + '">' + value.substring(0, 50) + '</span> ';
                                } else {
                                    return value;
                                }
                            }
                        },
                        { title: "数量", field: 'rppNum'},
/*                        { title: "实用", field: 'rppRealNum'},
                        { title: "余量", field: 'rppOverNum'},*/
                        { title: "单位", field: 'rppUnit'},
                        { title: "标准号", field: 'rppStandardNo'},
                        { title: "分类", field: 'rppTypes'},
                        { title: "品牌", field: 'rppBrand'},
                        { title: "备注", field: 'rppRemark', width: '60px'},
                        { title: "项目编号", field: 'rppProjectCode'},
                        { title: "项目名称", field: 'rppProjectName'},
                        {
                            title: "提报状态", field: 'rppUseStock',
                            formatter: function (value, row, index) {
                                if (value) {
                                    return '<span class="badge ' + reportColors[value] + '">' + reportState[value] + '</span> ';
                                }
                            }
                        },
                        {
                            title: "生产状态", field: 'rppProjectState',
                            formatter: function (value, row, index) {
                                if (value) {
                                    return '<span class="badge ' + projectColors[value] + '">' + projectState[value] + '</span> ';
                                }
                            }
                        },
                        { title: "计划号", field: 'rppPlanNo'},
                        { title: "提报日期", field: 'rppCreateTime', width: '90px'},
                    ]
                });
            },
            columns: [
                {
                    checkbox: true,
                    width: '30px',
                    formatter: function (value, row, index) {
                        // 正常提报并且数据正常状态可以提交选择
                        if (row.rppStatus === 2 && row.rppUseStock === 2) {
                            return {disabled: false}
                        } else {
                            return {disabled: true}
                        }
                    }
                },
                {
                    title: '序号', field: 'id', width: '50px',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                { title: "计划员", field: 'rppPlanner'},
                { title: "物料描述", field: 'rppMatDesc',
                    formatter: function (value, row, index, field) {
                        if (value && value.length > 50) {
                            return '<span title="' + value + '">' + value.substring(0, 50) + '</span> ';
                        } else {
                            return value;
                        }
                    }
                },
                { title: "数量", field: 'rppNum'},
/*                { title: "实用", field: 'rppRealNum'},
                { title: "余量", field: 'rppOverNum'},*/
                { title: "单位", field: 'rppUnit'},
                { title: "标准号", field: 'rppStandardNo'},
                { title: "分类", field: 'rppTypes'},
                { title: "品牌", field: 'rppBrand'},
                { title: "备注", field: 'rppRemark', width: '60px'},
                { title: "项目编号", field: 'rppProjectCode'},
                { title: "项目名称", field: 'rppProjectName'},
                {
                    title: "提报状态", field: 'rppUseStock',
                    formatter: function (value, row, index) {
                        if (value) {
                            return '<span class="badge ' + reportColors[value] + '">' + reportState[value] + '</span> ';
                        }
                    }
                },
                {
                    title: "生产状态", field: 'rppProjectState',
                    formatter: function (value, row, index) {
                            return '<span class="badge ' + projectColors[value] + '">' + projectState[value] + '</span> ';
                    }
                },
                { title: "计划号", field: 'rppPlanNo'},
                { title: "生产编号", field: 'rppProduceCode'},
                { title: "提报日期", field: 'rppCreateTime', width: '90px'},
                {
                    title: "操作",
                    width: '110px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // 改计划员
                        /*if (hasP('buy:planedit:change')) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditPlannerModal(' + js.jsonStringify(row) + ')"> 编辑</a> ');
                        }*/
                        if (sessionUser.name == row.rppPlanner || '管理员' == sessionUser.name) {
                            // 未提交状态
                            if (row.rppStatus === 2) {
                                // 未提交， 已指定 可以查看
                                if (row.rppIsFlag === 1 && hasP("buy:planedit:assign")) {
                                    actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="openMarkInfoModal(' + js.jsonStringify(row) + ')"> 查看</a> ');
                                }
                                // 未提交，未标记的可以修改
                                if (row.rppIsFlag === 0 && hasP("buy:planedit:edit")) {
                                    actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditReportPlanModal(' + row.rppId + ',' + row.rppOriginalFlag + ')"> 修改</a> ');
                                }
                                // 未提交， 未标记的可以拆分
                                if (row.rppIsFlag === 0 && hasP("buy:planedit:edit")) {
                                    actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="openSplitModal(' + js.jsonStringify(row) + ')"> 拆分</a> ');
                                }
                                // 未提交， 正常提报可以提交
                                if (row.rppUseStock === 2 && hasP("buy:planedit:edit")) {
                                    actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="commitReportPlan(' + row.rppId + ')"> 提交</a> ');
                                }
                                // 未提交， 使用库存，可以标记
                                if (row.rppUseStock === 1 && hasP("buy:planedit:assign")) {
                                    actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="openMarkReportPlanModal(' + js.jsonStringify(row) + ')"> 指定</a> ');
                                }
                                // 未指定， 未提交， 原始计划的可以删除
                                if (row.rppOriginalFlag === 1 && row.rppIsFlag === 0 && hasP("buy:planedit:del")) {
                                    actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="deleteReportPlan(' + row.rppId + ')"> 删除</a> ');
                                }
                            } else if (row.rppStatus === 3) { // 已提交状态
                                // 已提交， 正常提报，采购计划未提交的可以撤消
                                if ((!row.sppStatus || row.sppStatus === 1) && row.rppUseStock === 2 && hasP("buy:planedit:edit")) {
                                    actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="cancelReportPlan(' + row.rppId + ')"> 撤消</a> ');
                                }
                                // 已提交， 正常提报的可以变更
                                if (row.rppUseStock === 2 && row.rppSppId == null && hasP("buy:planedit:edit")) {
                                    actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditReportPlanModal(' + row.rppId + ',' + row.rppOriginalFlag + ')"> 修改</a> ');
                                }
                                // 已提交， 正常提报的可以变更
                                if (row.rppUseStock === 2 && row.rppSppId != null && hasP("buy:planedit:alter")) {
                                    actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openChangeReportPlanModal(' + row.rppId + ')"> 变更</a> ');
                                }
                            }
                        }
                        return actions.join('');
                    }
                }
            ]
        });


        /** 表格搜索 */
        $("#btn-search").click(function () {
            js.table.search(table);
            js.table.refresh(batchTable);
        });


        /** 添加表单验证规则 */
        js.validate.init("createReportPlanForm", {
            fields: {
                rppProjectCode: {
                    validators: {
                        notEmpty: {message: '请输入项目编号'},
                        remote: {
                            url: ctx + "buy/editReportPlan/checkProjectCode",
                            message: '项目编号不存在',
                            delay: 500,
                            type: 'POST'
                        },
                    }
                },
                rppProjectName: {validators: {notEmpty: {message: '请输入项目名称'}}},
                rppMatDesc: {validators: {notEmpty: {message: '请输入物料描述'}}},
                rppNum: {validators: {notEmpty: {message: '请输入数量'}}},
                rppUnit: {validators: {notEmpty: {message: '请输入单位'}}},
            }
        });
        /** 添加模态框隐藏事件 */
        js.modal.hideEvent("modal-create", function () {
            js.validate.reset("createReportPlanForm");
            js.reset("createReportPlanForm");
        });
        /** 添加提报计划 */
        $("#btn-create-report-plan").click(function () {
            js.validSubmit({
                formId: "createReportPlanForm",
                url: ctx + "buy/editReportPlan/create",
                data: new FormData($("#createReportPlanForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-create");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });


        /** 导入表单验证 */
        js.validate.init("importForm", {
            fields: {
                file: {
                    validators: {
                        notEmpty: {message: '上传文件不能为空'},
                        file: {extension: 'xls,xlsx', message: '请选择excel文件'}
                    }
                }
            }
        });
        /** 导入模态框隐藏事件 */
        js.modal.hideEvent("modal-import", function () {
            js.validate.reset("importForm");
            js.reset("importForm");
        });
        /** 导入提报计划 */
        $("#btn-upload").click(function () {
            var $this = $(this);
            $this.attr('disabled', true);
            js.validSubmit({
                formId: "importForm",
                url: ctx + "buy/editReportPlan/import",
                data: new FormData($("#importForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        if (result.msg == '导入完成') {
                            js.modal.hide("modal-import");
                        }
                        js.table.refresh(table);
                        // js.modal.hide("modal-import");
                        $this.attr('disabled', false);
                    }
                }
            });
        });
        /** 下载导入失败excel */
        $("#download-error").click(function () {
            var that = $(this);
            js.post({
                url: ctx + "buy/editReportPlan/exist",
                async: false,
                data: {
                    url: that.attr("data-url")
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        that.attr("href", that.attr("data-url") + "?timeStamp=" + new Date().getTime());
                    } else {
                        js.modal.warning("没有需要处理的文件");
                    }
                }
            });
        });


        /** 暂缓导入表单验证 */
        js.validate.init("importFormUpdate", {
            fields: {
                file: {
                    validators: {
                        notEmpty: {message: '上传文件不能为空'},
                        file: {extension: 'xls,xlsx', message: '请选择excel文件'}
                    }
                }
            }
        });
        /** 暂缓导入模态框隐藏事件 */
        js.modal.hideEvent("modal-import-update", function () {
            js.validate.reset("importFormUpdate");
            js.reset("importFormUpdate");
        });
        /** 暂缓导入提报计划 */
        $("#btn-upload-update").click(function () {
            var $this = $(this);
            $this.attr('disabled', true);
            js.validSubmit({
                formId: "importFormUpdate",
                url: ctx + "buy/editReportPlan/import/edit",
                data: new FormData($("#importFormUpdate")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        if (result.msg == '导入完成') {
                            js.modal.hide("modal-import");
                        }
                        js.table.refresh(table);
                        // js.modal.hide("modal-import");
                        $this.attr('disabled', false);
                    }
                }
            });
        });
        /** 下载暂缓导入失败excel */
        $("#download-error-update").click(function () {
            var that = $(this);
            js.post({
                url: ctx + "buy/editReportPlan/exist",
                async: false,
                data: {
                    url: that.attr("data-url")
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        that.attr("href", that.attr("data-url") + "?timeStamp=" + new Date().getTime());
                    } else {
                        js.modal.warning("没有需要处理的文件");
                    }
                }
            });
        });


        /** 修改计划员表单验证规则 */
        js.validate.init("editPlannerForm", {
            fields: {
                rppPlanner: {validators: {notEmpty: {message: '请输入计划员'}}}
            }
        });
        /** 修改计划员 */
        $("#btn-edit-planner").click(function () {
            js.validSubmit({
                formId: "editPlannerForm",
                url: ctx + "buy/editReportPlan/edit/planner",
                data: new FormData($("#editPlannerForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        if (mapTable) {
                            js.table.refresh(mapTable);
                        }
                        js.modal.hide("modal-edit-planner");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        /** 修改计划员模态框隐藏事件 */
        js.modal.hideEvent("modal-edit-planner", function () {
            js.validate.reset("editPlannerForm");
            js.reset("editPlannerForm");
        });


        /** 修改提报计划信息表单验证规则 */
        js.validate.init("editReportPlanForm", {
            fields: {
                rppPlanner: {validators: {notEmpty: {message: '请输入计划员'}}},
                rppMatDesc: {validators: {notEmpty: {message: '请输入物料描述'}}},
                rppProjectName: {validators: {notEmpty: {message: '请输入项目名称'}}}
            }
        });
        /** 修改提报计划模态框隐藏事件 */
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("editReportPlanForm");
            js.reset("editReportPlanForm");
        });
        /** 修改提报计划 */
        $("#btn-edit-report-plan").click(function () {
            // 非原材料类型，有余量没有实用数量的给出提示
            let typeName = $("#editReportPlanForm select[name=rppTypeId]").find("option:selected").text();
            let overNum = $("#editReportPlanForm input[name=rppOverNum]").val();
            let realNum = $("#editReportPlanForm input[name=rppRealNum]").val();
            if (typeName != '原材料' && overNum && !realNum) {
                js.modal.warning("请添写实用数量");
                return;
            }
            js.validSubmit({
                formId: "editReportPlanForm",
                url: ctx + "buy/editReportPlan/edit",
                data: new FormData($("#editReportPlanForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        if (mapTable) {
                            js.table.refresh(mapTable);
                        }
                        js.modal.hide("modal-edit");
                        js.modal.hide("modal-edit-split");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });


        /** 修改拆分后的提报计划信息表单验证规则 */
        js.validate.init("editSplitReportPlanForm", {
            fields: {
                rppNum: {validators: {notEmpty: {message: '请输入数量'}}}
            }
        });
        /** 修改提报计划模态框隐藏事件 */
        js.modal.hideEvent("modal-edit-split", function () {
            js.validate.reset("editSplitReportPlanForm");
            js.reset("editSplitReportPlanForm");
        });
        /** 修改提报计划 */
        $("#btn-edit-split-report-plan").click(function () {
            var srcNum = +$("#srcNum").text();
            var alreadySplitNum = +$("#alreadySplitNum").text();
            var currNum = +$("#editSplitReportPlanForm input[name=rppNum]").val();
            if (alreadySplitNum + currNum !== srcNum) {
                js.modal.confirm("拆分数据总数量与原数量不符，继续修改吗？", () => {
                    update();
                });
            } else {
                update();
            }
        });


        /** 追加拆分表单 */
        $("#btn-append").click(function () {
            $("#div-append").append(
                `
                <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <div class="col-md-12">
                                <input type="text" class="form-control" name="desc" autocomplete="off" placeholder="物料描述">
                            </div>

                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <div class="col-md-12">
                                <input type="number" step="0.1" class="form-control" name="num" placeholder="拆分数量">
                            </div>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <div class="col-md-12">
                                <select class="form-control" name="status" title="">
                                    <option value="2" selected>正常提报</option>
                                    <option value="1">使用库存</option>
                                    <option value="3">暂不提报</option>
                                    <option value="0">无状态</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <div class="col-md-12">
                                <input type="text" class="form-control" name="remark" autocomplete="off" placeholder="备注">
                            </div>
                        </div>
                    </div>
                    <div class="col-md-1">
                        <div class="form-group">
                            <div class="col-md-12">
                                <button type="button" class="btn btn-danger btn-append-del">删除</button>
                            </div>
                        </div>
                    </div>
                </div>
                `
            );
            $("#splitForm input[name=desc]").val($("#splitForm span[id=rppMatDesc]").text());
        });
        /** 追加表单删除 */
        $('#splitForm').on('click','.btn-append-del', function () {
            $(this).parents(".row:first").remove();
        });
        /** 拆分提报计划 */
        $("#btn-split").click(function () {
            if (!validNum()) {
                js.modal.confirm("拆分数量与原数量不符，是否继续？", () => split());
            } else {
                split();
            }
        });
        /** 拆分模态框隐藏事件 */
        js.modal.hideEvent("modal-split", function () {
            js.reset("splitForm");
            $("#div-append").empty();
        });
        /** 报报计划拆分关系表 */
        mapTable = js.table.init({
            id: "map-table",
            showColumns: false,
            queryForm: 'mapForm',
            url: ctx + "buy/editReportPlan/map",
            firstLoad: false,
            toolbar: '',
            rowStyle: function (row) {
                if (row.rppOriginalFlag === 3) {
                    return {
                        classes: 'danger'
                    };
                } else {
                    return {};
                }
            },
            columns: [
                {
                    title: '序号', field: 'id', width: '40',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                { title: "计划员", field: 'rppPlanner'},
                { title: "物料描述", field: 'rppMatDesc'},
                { title: "数量", field: 'rppNum'},
                { title: "单位", field: 'rppUnit'},
                // { title: "标准号", field: 'rppStandardNo'},
                // { title: "分类", field: 'rppTypes'},
                // { title: "品牌", field: 'rppBrand'},
                // { title: "备注", field: 'rppRemark'},
                { title: "项目编号", field: 'rppProjectCode'},
                { title: "项目名称", field: 'rppProjectName'},
                {
                    title: "提报状态", field: 'rppUseStock',
                    formatter: function (value, row, index) {
                        if (value) {
                            return reportState[value];
                        }
                    }
                },
                // { title: "计划号", field: 'rppTypeId'},
                // { title: "提报日期", field: 'rppCreateTime', width: '90px'},
                {
                    title: "操作",
                    width: '100px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (sessionUser.name == row.rppPlanner || sessionUser.name == '管理员') {
                            if (row.rppOriginalFlag !== 3 && row.rppStatus === 2) {
                                // 未标记的可以修改
                                if (row.rppIsFlag === 0 && hasP("buy:planedit:edit")) {
                                    actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditReportPlanModal(' + row.rppId + ',' + row.rppOriginalFlag + ')"> 修改</a> ');
                                }
                            }
                        }

                        return actions.join('');
                    }
                }
            ]
        });
        /** 提报计划拆分关系表搜索 */
        $("#btn-map-search").click(function () {
            js.table.search(mapTable);
        });


        /** changeReportPlanForm 表单验证规则 */
        js.validate.init("changeReportPlanForm", {
            fields: {
                rppPlanner: {validators: {notEmpty: {message: '请输入计划员'}}},
                rppMatDesc: {validators: {notEmpty: {message: '请输入物料描述'}}},
                rppProjectName: {validators: {notEmpty: {message: '请输入项目名称'}}}
            }
        });
        /** 变更提报计划 */
        $("#btn-change-report-plan").click(function () {
            // 非原材料类型，有余量没有实用数量的给出提示
            let typeName = $("#changeReportPlanForm select[name=rppTypeId]").find("option:selected").text();
            let overNum = $("#changeReportPlanForm input[name=rppOverNum]").val();
            let realNum = $("#changeReportPlanForm input[name=rppRealNum]").val();
            if (typeName != '原材料' && overNum && !realNum) {
                js.modal.warning("请添写实用数量");
                return;
            }
            js.validSubmit({
                formId: "changeReportPlanForm",
                url: ctx + "buy/editReportPlan/change",
                data: new FormData($("#changeReportPlanForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        if (mapTable) {
                            js.table.refresh(mapTable);
                        }
                        js.modal.hide("modal-change");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        /** 变更提报计划模态框隐藏事件 */
        js.modal.hideEvent("modal-change", function () {
            js.validate.reset("changeReportPlanForm");
            js.reset("changeReportPlanForm");
        });


        /** 指定库存表 */
        markTable = js.table.init({
            id: "mark-table",
            toolbar: '',
            showColumns: false,
            queryForm: 'markForm',
            pagination: false,
            url: ctx + "buy/editReportPlan/mark/list",
            firstLoad: false,
            columns: [
                {
                    checkbox: true,
                    formatter: function (value, row, index) {
                        if ($("#markForm input[name=info]").val()) {
                            return {checked: true}
                        } else {
                            return {disabled: false}
                        }
                    }
                },
                { title: "物料描述", field: 'info'},
                { title: "数量", field: 'num'},
                { title: "标准号", field: 'standardNo'},
                { title: "项目编号", field: 'code'},
                { title: "项目名称", field: 'name'},
                { title: "调整类型", field: 'c'},
                { title: "库房类型", field: 'st'}
            ]
        });
        /** 指定库存表搜索 */
        $("#btn-mark-search").click(function () {
            js.table.search(markTable);
        });
        /** 提报计划指定库存 */
        $("#btn-mark").click(function () {
            // js.table.search(markTable);
            var arr = js.table.selectColumns(markTable, "id");
            if (arr.length < 1) {
                js.modal.warning("请选择库存标记");
                return;
            }
            var srcNum = +$("#markForm span[id=rppNum]").text();
            let a = js.table.selectColumns(markTable, "num");
            let b = a.map(v => +v);
            let c = b.reduce((x, y) => x + y);
            var descNum = js.table.selectColumns(markTable, "num").map((i, v) => +v).reduce((x, y) => x + y);
            if (srcNum !== descNum) {
                js.modal.confirm("指定数量与使用数量不符，是否继续？", () => { mark(); });
            } else {
                mark();
            }
        });
        /** 提报计划指定物料名称 */
        $("#btn-assign").click(function () {
            if (!$("#markForm input[name=rppAssignDesc]").val()) {
                js.modal.warning("请输入物料描述");
                return;
            }
            js.post({
                url: ctx + "buy/editReportPlan/assign",
                data: {
                    rppId: $("#markForm input[name=rppId]").val(),
                    rppAssignDesc: $("#markForm input[name=rppAssignDesc]").val()
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.modal.hide("modal-mark")
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        /** 指定库存框态框隐藏清除搜索条件 */
        js.modal.hideEvent("modal-mark", function () {
            js.reset("markForm");
        });
        /** 原计划 */
        reportPlanTable = js.table.init({
            id: "report-plan-table",
            url: false,
            pagination: false,
            showColumns: false,
            showExport: false,
            sidePagination: null,
            toolbar: null,
            columns: [
                { title: "计划员", field: 'rppPlanner'},
                { title: "物料描述", field: 'rppMatDesc'},
                { title: "数量", field: 'rppNum'},
                // { title: "实用", field: 'rppRealNum'},
                // { title: "余量", field: 'rppOverNum'},
                { title: "单位", field: 'rppUnit'},
                { title: "标准号", field: 'rppStandardNo'},
                { title: "分类", field: 'rppTypes'},
                { title: "品牌", field: 'rppBrand'},
                { title: "备注", field: 'rppRemark'},
                { title: "项目编号", field: 'rppProjectCode'},
                { title: "项目名称", field: 'rppProjectName'},
                {
                    title: "提报状态", field: 'rppUseStock',
                    formatter: function (value, row, index) {
                        if (value) {
                            return '<span class="badge ' + reportColors[value] + '">' + reportState[value] + '</span> ';
                        }
                    }
                },
                {
                    title: "生产状态", field: 'rppProjectState',
                    formatter: function (value, row, index) {
                        if (value) {
                            return '<span class="badge ' + projectColors[value] + '">' + projectState[value] + '</span> ';
                        }
                    }
                },
                { title: "计划号", field: 'rppPlanNo'},
                { title: "提报日期", field: 'rppCreateTime', width: '90px'},
                { title: "指定物料", field: 'rppAssignDesc'},
            ]
        });
        /** 指定信息 */
        markInfoTable = js.table.init({
            id: "mark-info-table",
            showExport: false,
            showColumns: false,
            toolbar: null,
            firstLoad: false,
            columns: [
                { title: "物料描述", field: 'info'},
                { title: "数量", field: 'num'},
                { title: "单位", field: 'unit'},
                { title: "项目编号", field: 'code'},
                { title: "项目名称", field: 'name'},
                { title: "调整类型", field: 'c'},
                { title: "库房类型", field: 'st'}
            ]
        });


        /** 初始化搜索条件 */
        $("#batchForm input[name=rppPlanner]").val(sessionUser.name);
        // $("#batchForm input[name=rppStatus]").val(2);
        // $("#batchForm input[name=rppIsFlag]").val(0);

        js.table.refresh(table);
        /** 批量修改提报状态表搜索 */
        $("#btn-batch-search").click(function () {
            js.table.search(batchTable);
        });

        /** 导出 */
        $("#a-export").click(function () {
            $("#queryForm").submit();
            js.modal.loading("正在导出，请稍候");
            setTimeout(function () {
                js.modal.closeLoading();
            }, 5000);
        });


        /** 外购件批量指定表格 */
        outAssignTable = js.table.init({
            id: "out-assign-table",
            toolbar: '#out-assign-bar',
            showColumns: false,
            queryForm: 'outAssignForm',
            url: ctx + "buy/editReportPlan/list/outAssign",
            firstLoad: false,
            columns: [
                {
                    checkbox: true,
                    width: '30px'
                },
                {
                    title: '序号', field: 'id', width: '50px',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                // { title: "计划员", field: 'rppPlanner'},
                { title: "提报项目编号", field: 'rppProjectCode'},
                { title: "提报项目名称", field: 'rppProjectName'},
                { title: "物料描述", field: 'rppMatDesc',
                    formatter: function (value, row, index, field) {
                        if (value && value.length > 50) {
                            return '<span title="' + value + '">' + value.substring(0, 50) + '</span> ';
                        } else {
                            return value;
                        }
                    }
                },
                { title: "数量", field: 'rppNum'},
                // { title: "单位", field: 'rppUnit'},
                { title: "标准号", field: 'rppStandardNo'},
                // { title: "分类", field: 'rppTypes'},
                { title: "品牌", field: 'rppBrand'},
                { title: "备注", field: 'rppRemark', width: '60px'},

                // { title: "计划号", field: 'rppPlanNo'},
                // { title: "提报日期", field: 'rppCreateTime', width: '90px'},
                { title: "指定项目编号", field: 'code', width: '80px'},
                { title: "指定项目名称", field: 'name', width: '120px'},
                { title: "指定物料描述", field: 'info', width: '120px'},
                { title: "指定数量", field: 'num', width: '60px'},
                { title: "指定标准号", field: 'standardNo', width: '90px'},
                {
                    title: "操作",
                    width: '60px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP('buy:planedit:assign')) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="outAssign(' + row.rppId + ')"> 指定</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });


        /** 指定采购计划表格 */
        assignPlanTable = js.table.init({
            id: "assign-plan-table",
            toolbar: null,
            showExport: false,
            showColumns: false,
            paginationVAlign: 'top',
            queryForm: 'assignPlanForm',
            url: ctx + "buy/editReportPlan/list/buy",
            pageSize: 10,
            firstLoad: false,
            columns: [
                {
                    title: '序号', field: 'id', width: '50px',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                { title: "SAP<br>物料编号", field: 'sppSapCode'},
                { title: "采购<br>物料描述", field: 'sppMatDesc'},
                { title: "提报<br>数量", field: 'num'},
                { title: "采购<br>数量", field: 'sppNum'},
                { title: "品牌", field: 'sppBrand'},
                { title: "备注<br>计划用途", field: 'sppProjectName',width: '180px'}, // （相当于采购计划备注，导入OA时用，有字数限制，不超过40字）
                { title: "计划<br>采购日期", field: 'sppPlanDate',width: '90px'},
                {
                    title: "操作",
                    width: '60px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP('buy:planedit:assign')) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="assignPlanApply(' + row.sppId + ')"> 指定</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });
        /** 指定计划表格搜索 */
        $("#btn-assign-plan-search").click(function () {
            js.table.search(assignPlanTable);
        });
    });

</script>
</body>
</html>
